package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id来查询床位")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }
    //床位新增
    @PostMapping("/create")
    @ApiOperation(value = "床位新增",notes = "传入BedDto实体类新增数据")
    public ResponseResult addBed(@ApiParam(value = "新增数据的实体类",required = true) @RequestBody BedDto bedDto){
        int i = bedService.addBed(bedDto);
        return toAjax(i);
    }
    //根据id查询(修改前的数据回显)
    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据Id查询床位",notes = "传入房间Id来查询床位")
    public ResponseResult selectById(@ApiParam(value = "房间Id",required = true)@PathVariable("id") Long id){
        BedVo bedVo = bedService.selectById(id);
        return success(bedVo);
    }
    //修改床位
    @PutMapping("/update")
    @ApiOperation(value = "修改床位",notes = "根据传入信息修改床位信息")
    public ResponseResult updateBed(@ApiParam(value = "修改信息",required = true)@RequestBody BedDto bedDto){
        int i = bedService.updateBed(bedDto);
        return toAjax(i);
    }
    //删除床位
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除床位",notes ="根据传入Id删除床位" )
    public ResponseResult deleteById(@ApiParam(value = "床位Id",required = true)@PathVariable("id") Long id){
        int i = bedService.deleteById(id);
        return toAjax(i);
    }
}
